function handleError(errMsg) {
	$('#errMsgModal').modal('show');
	$('#errMsgModal').find('.modal-body').html('').append('<p>' + errMsg + '</p>');
}

function notifyDefaultInternalErr() {
	$.notify({
		title : '<strong>Internal Error</strong>',
		message : 'The desired function could not be completed.Please contact administrator.'
	}, {
		type : 'danger',
		delay : 1500,
		placement : {
			from : "bottom",
			align : 'right'
		},
		z_index : 9999,
		animate : {
			enter : 'animated fadeInDown',
			exit : 'animated fadeOutUp'
		},
	});
}

function handleSuccess(msg) {
	$.notify({
		title : '<strong>Notification</strong>',
		message : msg
	}, {
		type : 'success',
		delay : 1500,
		placement : {
			from : "bottom",
			align : 'right'
		},
		z_index : 9999,
		animate : {
			enter : 'animated fadeInDown',
			exit : 'animated fadeOutUp'
		},
	});
}

function notifyDanger(msg) {
	$.notify({
		title : '<strong>Notification</strong>',
		message : msg
	}, {
		type : 'danger',
		delay : 1500,
		placement : {
			from : "bottom",
			align : 'right'
		},
		z_index : 9999,
		animate : {
			enter : 'animated fadeInDown',
			exit : 'animated fadeOutUp'
		},
	});
}

function setMapLabel(node, event, mapType, sn, ts, hd) {
	if (event.shiftKey == 1) {
		
	}
	var nodeSuffix = "_" + mapType + "_" + sn + "_" + ts + "_" + hd;
	var labelObjId = "";
	var radios = document.getElementsByName('mapLabeRadios' + nodeSuffix);
	for (var i = 0, length = radios.length; i < length; i++) {
		if (radios[i].checked) {
			labelObjId = radios[i].value;
			break;
		}
	}
	$(node).closest('tr').find('div[id="mapLabelDiv' + nodeSuffix + '"]').find('span').removeClass("text-success").removeClass("font-weight-bold");
	$('input[name="mapLabeRadios' + nodeSuffix + '"]:checked').closest('div').find('span').addClass("text-success").addClass("font-weight-bold");
	$('#myPleaseWait').modal('show');
	$.ajax({
		type : "POST",
		url : "label/setMapLabel.do",
		data : {
			"mapType" : mapType,
			"sn" : sn,
			"ts" : ts,
			"hd" : hd,
			"labelObjId" : labelObjId
		},
		dataType : "json",
		success : function(json) {
			setTimeout(function() {
				$('#myPleaseWait').modal('hide')
			}, 500);
			if (json.success) {
				var labelName = (json.rtnVal)[0];
				var updatedBy = (json.rtnVal)[1]
				var map = (json.rtnVal)[3]
				handleSuccess(sn + " set " + map + " label to " + labelName);
				$(node).parent(0).find('.mapLabeledBySpan').html('Last labeled by ' + updatedBy);

				refreshLabelList();
			} else {
				notifyDefaultInternalErr();
			}
		},
		error : function(xhr, ajaxOptions, thrownError) {
		}
	});
}

function manualZoom(mapType, sn, ts, head, failCode, polar) {
	var win = window.open('http://' + window.location.host + '/FlawScanAnalytic/plot/manualZoom.do?mapType=' + mapType + '&sn=' + sn + '&ts=' + ts + '&head=' + head + '&failCode=' + failCode
			+ '&polar=' + polar, '_blank');

}

// will over write if necessary in some page
function refreshLabelList() {
}

function openReleaseNote() {
	window.open('http://' + window.location.host + '/FlawScanAnalytic/releaseNoteMain.do', '_blank');
}